#!/usr/bin/perl

my $input_path = "D:\\kevinvid4\\datasets\\SEDSUB\\cam1";
my $output_path = "D:\\formal";
my $cam = "1";

my $train_path = "$input_path\\training";
my $test_path = "$input_path\\testing";

my $prob_path = "$output_path\\prob";
my $pred_path = "$output_path\\pred";
my $smoothed_path = "$output_path\\smoothed";

my $jar_file = "BiasedClassifier.jar";
my $classify_main = "batch.BatchClassifier";
my $balance_main = "batch.BatchBalancer";
my $smooth_main = "batch.BatchSmoother";

my $classifier = "gaussian";

my @event_names = ("", "PersonRuns", "CellToEar", "Embrace", "ObjectPut", "PeopleMeet", "PeopleSplitUp", "Pointing");
my @alphabets = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j');
my @last_list = ('i', 'j', 'j', 'j', 'g', 'i', 'g', 'j', 'j', 'i', 'i', 'g');

open(my $bat, ">", "Cam$cam.bat") or die;

for(my $event = 1; $event <= 7;  $event++) {
	
	my $file_list = "Cam$cam.Event$event.txt";
	open(my $out, ">", $file_list) or die;

	print $out "$train_path\\dev08.$event_names[$event]\n"; #train file
	
	my $eval_filename = "eval08_some.$event_names[$event]";
	print $out "$train_path\\$eval_filename $prob_path\\$eval_filename\n"; #eval file

	for(my $i = 1; $i <= 12; $i++) {
		
		my $last_alpha = $last_list[$i - 1];
		
		foreach my $alpha (@alphabets) {
			if($alpha le $last_alpha) {
				my $num;
				if($i < 10) {
					$num = "0$i";
				} else {
					$num = "$i";
				}
			
				my $filename = "MCTTR".$num."0".$cam."$alpha.test";
				my $output_filename = "Cam".$cam."0.$event.$filename.output";
				
				my $raw_file = "$test_path\\$filename";
				my $prob_file = "$prob_path\\$output_filename";
				my $pred_file = "$pred_path\\$output_filename";
				my $smoothed_path = "$smoothed_path\\$output_filename";
				
				print $out "$raw_file $prob_file $pred_file $smoothed_path\n";
			}
		}
	}
	close $out;
	
	my $pipe_file = "Cam$cam.Event$event.bat";
	open(my $pipe, ">", $pipe_file) or die;
	
	print $pipe "java -Xmx1000m -cp $jar_file $classify_main $classifier $file_list 2000\n";
	print $pipe "java -Xmx1000m -cp $jar_file $balance_main $file_list max_ndcr\n";
	print $pipe "java -Xmx1000m -cp $jar_file $smooth_main $file_list window_vote 2\n";
	
	close $pipe or die;
	
	print $bat "start $pipe_file\n";
}

close $bat;

